package com.ziyue.socket.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ziyue.socket.bean.answer.AnswerFinishRequest;
import com.ziyue.socket.bean.change.ChangeActivityRequest;
import com.ziyue.socket.bean.change.ChangeActivityResponse;
import com.ziyue.socket.cache.ChangeService;
import com.ziyue.socket.enums.OptionEnum;
import com.ziyue.socket.exception.UnFullWebsocketMessageException;
import com.ziyue.socket.service.OptionAbstract;
import io.netty.channel.Channel;

/**
 * Created by wancheng on 2019/4/20.
 */
public class ChangeActivity extends OptionAbstract {

    private final OptionEnum OPTION = OptionEnum.CHANGE_ACTIVITY;

    @Override
    public Object send(Channel channel, String requestBody) throws Exception {
        ChangeActivityRequest request = JSONObject.parseObject(requestBody, ChangeActivityRequest.class);
        if (request.getActivityId() == null){
            throw  new UnFullWebsocketMessageException("无互动id");
        }

        ChangeService.changeActivity(channel,request.getActivityId());
        sendStudent(channel,"更换当前互动id",new ChangeActivityResponse(request.getActivityId()),OPTION);
        return null;
    }

    @Override
    public Object get(Channel channel, String requestBody) {
        return null;
    }
}
